<template>
  <view>
    <view class="search_box">
      <my-search @click="gotoSearch"></my-search>
    </view>
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
      <swiper-item v-for="(item,index) in swiperList" :key="index">
        <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
          <image :src="item.image_src" mode="aspectFill"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <view class="nav-list">
      <view class="nav-item" v-for="(item,index) in navList" :key="index" @click="navClickHandler(item)">
        <image :src="item.image_src" mode=""></image>
      </view>
    </view>
    <view class="floor-list">
      <view class="floor-item" v-for="(item,index) in floorList" :key="index">
        <image class="floor-title" v-if="item.floor_title" :src="item.floor_title.image_src" mode=""></image>
        <view class="floor-img-box">
          <view class="left-img-box">
            <navigator :url="item.product_list[0].url">
              <image :src="item.product_list[0].image_src" mode="widthFix"
                :style="{width:item.product_list[0].image_width+'rpx'}"></image>
            </navigator>
          </view>
          <view class="right-img-list">
            <view class="right-img-item" v-for="(item2,index2) in item.product_list" :key="index2" v-if="index2!==0">
              <navigator :url="item2.url">
                <image :src="item2.image_src" mode="widthFix" :style="{width:item2.image_width+'rpx'}"></image>
              </navigator>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import badgeMix from '@/mixins/tabbar-badge.js'
  export default {
    mixins: [badgeMix],
    data() {
      return {
        //轮播图
        swiperList: [],
        //分类导航
        navList: [],
        //楼层的数据列表
        floorList: []
      }
    },
    onLoad() {
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    },
    methods: {
      async getSwiperList() {
        //解构赋值data并重命名为res
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/swiperdata')
        // console.log(res)
        if (res.meta.status !== 200) {
          return uni.$showMsg();
        }
        this.swiperList = res.message;
      },
      async getNavList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/catitems')
        // console.log(res)
        if (res.meta.status !== 200) {
          return uni.$showMsg()
        }
        this.navList = res.message
      },
      async getFloorList() {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/floordata')
        if (res.meta.status !== 200) {
          return uni.$showMsg();
        }

        res.message.forEach((floor) => {
          floor.product_list.forEach((item) => {
            item.url = '/subpkg/goods_list/goods_list?' + item.navigator_url.split('?')[1];
          })
        })
        this.floorList = res.message;
      },
      navClickHandler(item) {
        if (item.name === '分类') {
          uni.switchTab({
            url: '/pages/cate/cate'
          })
        }
      },
      gotoSearch() {
        uni.navigateTo({
          url: '/subpkg/search/search'
        })
      }

    }

  }
</script>

<style lang="scss" scoped>
  .search_box {
    position: sticky;
    top: 0;
    z-index: 999;
  }

  swiper {
    height: 360rpx;

    .swiper-item,
    image {
      width: 100%;
      height: 100%;
    }
  }

  .nav-list {
    display: flex;
    justify-content: space-around;
    margin: 15rpx 0;

    .nav-item {
      image {
        width: 128rpx;
        height: 140rpx;
      }
    }
  }

  .floor-list {
    .floor-item {
      .floor-title {
        height: 60rpx;
        width: 100%;
        display: flex;
      }
    }

    .floor-img-box {
      display: flex;


      .left-img-box {
        display: flex;
        align-items: center;



        image {
          border-radius: 15rpx;
          border: 1rpx solid #fff;
        }
      }

      .right-img-list {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-around;
        align-content: space-between;
        padding-left: 10rpx;


        .right-img-item {
          display: flex;
          align-items: center;


          image {
            border-radius: 15rpx;
            border: 1rpx solid #fff;
          }
        }
      }
    }
  }
</style>
